<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Exceptions\HttpResponseException;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if ($request->is('api/*')) {
            logger('request:' . $request->path());
            logger('request:' . json_encode($request->header()));

            throw new HttpResponseException(error('未登录', 401));
        } else {
            logger('fail-request' . json_encode(request()));
            // return route('login');
        }
        /*
        if (! $request->expectsJson()) {
            return route('login');
        }
        */
    }
}
